import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/sys/user/list',
  save = '/sys/user/add',
  edit = '/sys/user/edit',
  deleteOne = '/sys/user/delete',
  deleteBatch = '/sys/user/deleteBatch',
  importExcel = '/sys/user/importExcel',
  exportXls = '/sys/user/exportXls',
  userDepartList = '/sys/user/userDepartList',
  allPostList = '/sys/position/list',
  countAll = '/sys/user/countAll',
  countEdu = '/sys/user/countEdu',
  listFair='/cert/labCert/listFair',
  updateFair='/cert/labCert/updateFair',
  itemsList='/items/labItems/getItemsBasisList',
  skillList='/skill/labUserSkill/list',
  updateSkill='/skill/labUserSkill/updateUserSkills',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });
/**查询人员资质情况 */
export const listFair = (params) => defHttp.get({ url: Api.listFair, params });
/**查询总人数 */
export const countAll = (params) => defHttp.get({ url: Api.countAll, params },{successMessageMode:'none'});
/**查询学历分布 */
export const countEdu = (params) => defHttp.get({ url: Api.countEdu, params });
/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}
/**保存修改荣誉、资质 */
export const saveOrUpdateFlair = (params, isUpdate) => {
  let url =  Api.updateFair ;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

/**
 * 获取指定用户负责部门
 */
export const getUserDepartList = (params) => defHttp.get({ url: Api.userDepartList, params }, { successMessageMode: 'none' });
/**
 * 获取全部职务
 */
export const getAllPostList = (params) => {
  return new Promise((resolve) => {
    defHttp.get({ url: Api.allPostList, params }).then((res) => {
      resolve(res.records);
    });
  });
};


/**
 * 获取项目信息
 */
export const itemsList = (params) => defHttp.get({ url: Api.itemsList, params });

export const skillList = (params) => defHttp.get({ url: Api.skillList, params });

/**更新专业能力 */
export const updateSkill = (params) => {
  let url =  Api.updateSkill ;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}